/**
 * Created by lintao_alex on 2018/8/29
 */


namespace mengdao {
    import BaseContextObj = game.BaseContextObj;

    export abstract class BaseWindow extends BaseContextObj{
        abstract get ui():fairygui.GComponent;
        abstract get resPackage():string;
        abstract __createUI():void;
        protected beforeOpen():void{}//尚未加入显示列表,此时数据已就绪，可以刷新一些静态的显示
        protected afterOpen():void{}//面板已经完全展现出来，UI特效在此启动
        protected beforeClose():void{}//面板准备关闭
        protected afterClose():void{}//已从显示列表移除
        protected openAni(onAniEnd:Function, callObj?:any){
            if(!callObj) callObj = this;
            onAniEnd.apply(callObj);
        }
        protected closeAni(onAniEnd:Function, callObj?:any){
            if(!callObj) callObj = this;
            onAniEnd.apply(callObj);
        }

        __readyOpen(){
            this.beforeOpen();
        }
        public open(endCall:Function, callObj:any){
            this.openAni(()=>{
                this.afterOpen();
                this.active();
                endCall.apply(callObj);
            });
        }
        public close(endCall:Function, callObj:any){
            this.beforeClose();
            this.sleep();
            this.closeAni(()=>{
                endCall.call(callObj);
                this.afterClose();
            });
        }


        public requestData(onBack:IRequestBack){
            onBack.onSuccess.apply(onBack.callObj);
            // egret.setTimeout((lala)=>{
            //     readyCall.call(callObj);
            // }, this, 3000)
        }

        //TODO 特效获取接口，以便关闭UI时自动释放
        private _effectList:any[];
        public getEffect():any{
            return null;
        }
    }
}